package com.kaigejava.juc.toolsdemo.countdowlatchdemo;

import lombok.Data;

import java.util.concurrent.CountDownLatch;

/**
 * @author kaigejava
 * 模拟火箭发射前各个部门的线程。使用countdownlatch
 */
@Data
public class RocketDepartmCountDowunlatchentThread implements Runnable {


    private CountDownLatch count;
    /**
     * 部门名称
     */
    private String departmentName;
    @Override
    public void run() {
        synchronized (this){
            try {
                System.out.println("报告总控室,部门:"+getDepartmentName()+",准备就绪。");
            }catch (Exception e){

            }finally {
                //保证无论当前线程执行结果是什么。都要让count减一
                count.countDown();
            }
        }

    }

    public RocketDepartmCountDowunlatchentThread(){}

    public RocketDepartmCountDowunlatchentThread(String departmentName){
        this.departmentName = departmentName;
    }
    public RocketDepartmCountDowunlatchentThread(String departmentName, CountDownLatch count){
        this.departmentName = departmentName;
        this.count = count;
    }
}
